#!/bin/bash

current_dir=$(basedir $0)

version=17
soft_dir=/opt/softs
install_dir=/usr/local

# yum install java-1.8.0-openjdk wget -y

yum install -y wget unzip
cd ${soft_dir}
[ -f jdk-${version}_linux-x64_bin.tar.gz ] || wget https://download.oracle.com/java/${version}/latest/jdk-${version}_linux-x64_bin.tar.gz || exit 1

[ -d ${install_dir}/jdk-${version}* ] && rm -f ${install_dir}/jdk-${version}*
tar -xzvf jdk-${version}_linux-x64_bin.tar.gz -C ${install_dir}
mv ${install_dir}/jdk-${version}* ${install_dir}/jdk-${version}

[ -f /etc/profile.d/jdk-${version}.sh ] && exit 0


cp ${current_dir}/jdk.sh /etc/profile.d/jdk-${version}.sh
sed -i "s/jdk/jdk-${version}/g" /etc/profile.d/jdk-${version}.sh
chmod +x /etc/profile.d/jdk-${version}.sh
source /etc/profile.d/jdk-${version}.sh

java -version